#!/usr/bin/python3

try:
    t = int(input())
    for x in range(t):
        a_str = [item for item in input().split()]
        a = list(map(int, a_str))
        n = int(a[0])
        a.pop(0)
        a_str.pop(0)
        a_max = max(a)
        a_max_index = a.index(a_max)
        a_min = min(a)
        a_min_index = a.index(a_min)
        if a_max_index == n-1 and a_min_index == 0:
            a_str[0],a_str[n-1]=a_str[n-1],a_str[0]
        elif a_max_index == 0 and a_min_index != n-1:
            a_str[n - 1], a_str[a_min_index] = a_str[a_min_index], a_str[n - 1]
        elif a_max_index != 0 and a_min_index == n-1:
            a_str[0], a_str[a_max_index] = a_str[a_max_index], a_str[0]
        elif a_max_index != 0 and a_min_index != n - 1:
            if a_min_index == 0:
                a_str[0], a_str[a_max_index] = a_str[a_max_index], a_str[0]
                a_str[n - 1], a_str[a_max_index] = a_str[a_max_index], a_str[n - 1]
            elif a_max_index == n-1:
                a_str[n - 1], a_str[a_min_index] = a_str[a_min_index], a_str[n - 1]
                a_str[0], a_str[a_min_index] = a_str[a_min_index], a_str[0]
            else:
                a_str[0], a_str[a_max_index] = a_str[a_max_index], a_str[0]
                a_str[n - 1], a_str[a_min_index] = a_str[a_min_index], a_str[n - 1]

        ret = " ".join(a_str)
        print("Case #%d: %s" % (x + 1, ret))

except ValueError:
    pass
except IndexError:
    pass
except EOFError:
    pass
except MemoryError:
    pass
